from django import forms
from mac import models
from mac.forms import bootstrapform
from django.forms import widgets as ws


class JurisdictionAddForm(bootstrapform.BootStrapForm, forms.ModelForm):

    class Meta:
        model = models.Jurisdiction
        fields = '__all__'
        exclude = ['is_menu']


class JurisdictionEditForm(forms.ModelForm):

    class Meta:
        model = models.Jurisdiction
        fields = '__all__'
        exclude = ['is_menu']

    def __new__(cls, *args, **kwargs):
        for field_name in cls.base_fields:  # 字段都包含在了cls.base_fields中
            filed_obj = cls.base_fields[field_name]
            # 添加属性
            filed_obj.widget.attrs.update({'class': 'form-control'})
        return forms.ModelForm.__new__(cls)
